package com.lagou.service.impl;

import com.lagou.dao.TokenDao;
import com.lagou.pojo.Token;
import com.lagou.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @Author zhangbbk
 * @Description //TODO
 * @Date 2020/5/9 21:29
 **/
@Service
public class TokenServiceImpl implements TokenService {

    @Autowired
    private TokenDao tokenDao;

    @Override
    public String createToken() {
        //UUID
        UUID uuid = UUID.randomUUID();
        return uuid.toString();
    }

    @Override
    public void saveToken(String email, String token) {
        Token tk= new Token();
        tk.setEmail(email);
        tk.setToken(token);
        tokenDao.save(tk);
    }

    @Override
    public String getEmail(String token) {
        return tokenDao.findByToken(token).getEmail();
    }
}
